<template>
  <q-page>
    <object class='frame' :data='url' />
    <div class='btnGroup'>
      <q-btn v-for='(btn, index) in btnValue' :key='index' @click='toMpPage(btn)' color='yellow'>
        {{btn.operateEventName}}
      </q-btn>
    </div>
  </q-page>
</template>

<script lang='ts' setup>
import { onMounted,Ref , ref } from 'vue';
import { useRoute} from 'vue-router';
import { postRequest } from 'components/functions';
import wx from 'weixin-js-sdk-ts'
let url: Ref<string> = ref<string>('');
let btnValue = ref();



onMounted(() => {
  let queryUrl = 'channel/channel/operation';
  let query = useRoute().query;
  url.value = analyzeQuery(query.url)
  let queryParam = {
    companyId: analyzeQuery(query.companyId),
    entityCode: analyzeQuery(query.entityCode),
    entityType: analyzeQuery(query.entityType),
    groupEntityCode: analyzeQuery(query.groupEntityCode),
    objectCodeType: analyzeQuery(query.objectCodeType),
    sceneCode: analyzeQuery(query.sceneCode)
  }
  postRequest(queryUrl,queryParam,analyzeData)

})

function analyzeData (res) {
  btnValue.value = res

}

function analyzeQuery (inQuery:  string | string[]): string {
  let res = ''
  if (!!inQuery) {
    res = typeof inQuery === 'string' ?inQuery: inQuery[0]
  }
  return res;
}

function toMpPage (data) {
  //wx.miniProgram.navigateTo({url:  `/pages/operate/operate?entityCode=260&entityType=12&eventCode=002`})
  let operateEntity = data.operateEntity;
  let entityCode =  operateEntity.substring(0,3)
  let entityType =  operateEntity.substring(3,operateEntity.length)
  wx.miniProgram.navigateTo({url:  `/pages/operate/operate?entityCode=${entityCode}&entityType=${entityType}&eventCode=${data.operateEvent}`})
}


</script>

<style lang='scss' scoped>
.frame {
  width: 100vw;
  height: 100vh;
}
.btnGroup {
  display: flex;
  width: 100vw;
  justify-content: space-evenly;
  position: fixed;
  bottom: 3em;
}
</style>
